﻿using UnityEngine;
using System.Collections;
public delegate void UIAniVoidDelegateFloat(float f1);
[System.Serializable]
public class NGUIAnimBase{
	[SerializeField]AnimationCurve _curve;
	[SerializeField]float time;
	[SerializeField]WrapMode wrapmode;
	float t;
	float _savetime = 0;
	public UIAniVoidDelegateFloat OnUpdateValue;
	/// <summary>
	/// 具体的逻辑由各拓展类实现
	/// </summary>
	/// <param name="value">Value.</param>
	protected virtual void UpdateValue(float value){
		if (OnUpdateValue != null)
			OnUpdateValue (value);
	}
	public void Update(float dt){
		_savetime += dt;
		switch (wrapmode) {
		case WrapMode.Loop:
			t = _savetime % time / time;
			break;
		case WrapMode.PingPong:
			t = Mathf.PingPong (_savetime, time);
			break;
		default:
			t = Mathf.Clamp (_savetime / time, 0, 1);
			break;
		}

		UpdateValue (_curve.Evaluate(t));
	}
}
